{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from plotly.subplots import make_subplots\n",
    "import plotly.graph_objects as go\n",
    "import numpy as np\n",
    "\n",
    "q = np.linspace(-1,4,51)\n",
    "v = np.linspace(-1,4,51)\n",
    "f = np.zeros((len(q), len(v)))\n",
    "qn = np.zeros((len(q), len(v)))\n",
    "\n",
    "h = 0.1\n",
    "m = 1\n",
    "for i in range(len(q)):\n",
    "  for j in range(len(v)):\n",
    "    if (q[i] + h*v[j] >= 0):\n",
    "      qn[j, i] = q[i] + h*v[j]\n",
    "    else:\n",
    "      f[j, i] = -m*(q[i] + h*v[j])/h**2\n",
    "\n",
    "fig = make_subplots(\n",
    "  rows=1, cols=2,\n",
    "  specs=[[{'type': 'surface'}, {'type': 'surface'}]],\n",
    "  vertical_spacing = 0.0,\n",
    "  horizontal_spacing = 0.0\n",
    "  )\n",
    "\n",
    "fig.add_trace(go.Surface(\n",
    "    x = q,\n",
    "    y = v,\n",
    "    z = qn,   \n",
    "    colorscale=\"greys\",       \n",
    "    contours = {\n",
    "        \"x\": {\"start\": q[0], \"end\": q[-1], \"size\": 0.5, \"show\": True},\n",
    "        \"y\": {\"start\": v[0], \"end\": v[-1],\"size\": 0.5, \"show\": True},\n",
    "#        \"z\": {\"show\": True}\n",
    "    },\n",
    "    lighting = {\n",
    "      \"ambient\" : 1.0,\n",
    "      \"diffuse\" : 1.0,\n",
    "      \"specular\" : 0.0,\n",
    "    },\n",
    "    showscale = False,\n",
    "    ),\n",
    "    row=1, col=1)\n",
    "\n",
    "fig.add_trace(go.Surface(\n",
    "    x = q,\n",
    "    y = v,\n",
    "    z = f,   \n",
    "    colorscale=\"greys\",       \n",
    "    contours = {\n",
    "        \"x\": {\"start\": q[0], \"end\": q[-1], \"size\": 0.5, \"show\": True},\n",
    "        \"y\": {\"start\": v[0], \"end\": v[-1],\"size\": 0.5, \"show\": True},\n",
    "#        \"z\": {\"show\": True}\n",
    "    },\n",
    "    lighting = {\n",
    "      \"ambient\" : 1.0,\n",
    "      \"diffuse\" : 1.0,\n",
    "      \"specular\" : 0.0,\n",
    "    },\n",
    "    showscale = False,\n",
    "    ),\n",
    "    row=1, col=2)\n",
    "\n",
    "\n",
    "fig.update_layout(scene = {\n",
    "                    \"xaxis_title\" : 'q[n]',\n",
    "                    \"yaxis_title\" :'v[n]',\n",
    "                    \"zaxis_title\" :'q[n+1]'\n",
    "                  },\n",
    "                  scene_aspectmode='manual',\n",
    "                  scene_aspectratio=dict(x=1, y=1, z=.5),\n",
    "                  scene_camera={\n",
    "                    \"eye\": {\"x\": -1, \"y\": -2, \"z\": 0.5},\n",
    "                    \"center\": {\"x\": -.4, \"y\": -.4, \"z\": 0},\n",
    "                  },\n",
    "                  scene2 = {\n",
    "                    \"xaxis_title\" : 'q[n]',\n",
    "                    \"yaxis_title\" :'v[n]',\n",
    "                    \"zaxis_title\" :'f[n]'\n",
    "                  },\n",
    "                  scene2_aspectmode='manual',\n",
    "                  scene2_aspectratio=dict(x=1, y=1, z=.5),\n",
    "                  scene2_camera={\n",
    "                    \"eye\": {\"x\": -1, \"y\": -2, \"z\": 0.5},\n",
    "                     \"center\": {\"x\": -.4, \"y\": -.4, \"z\": 0},\n",
    "                 },\n",
    "                  margin={\"l\": 0, \"r\" : 0, \"t\": 0, \"b\": 0, \"pad\": 0}\n",
    "                )\n",
    "fig.write_html(\"../data/lcp_cart.html\")\n",
    "fig.show()\n",
    "\n",
    "# TODO: change z-axis label to subplot title"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
